define(function(require, exports){
	var pubjs	= require('pubjs');
	var popwin	= require('@base/dialog').base;
	var grid    = require('@base/grid').base;

	var Grid = grid.extend({
		init: function(config){
			config = pubjs.conf(config, {
				cols: [
					 {name:'_id', text: LANG("ID"), sort: true, 'align': 'center'}
					,{name:'Name', text: LANG("名称"), width: 600, render: 'renderName'}
					,{name:'op',text: LANG("操作"), type: 'op', render: 'renderOperate'}
				]
				,reqType: 'websocket'
				,opClick: true
				,hasTab: false
				,hasMenu: false
				,hasPager: true
				,hasSearch: true
				,hasExport: false
				,hasAmount: false
				,auto_load: false
				,param: {
					limit: 8
				}
				,pager: {
					size: 8
					,showSizeTypes: 0
					,showJumper: 0
				}
			});

			this.Super('init', arguments);
		}
		,renderName: function(i, val){
			return '<div class="uk-text-truncate tl" title="' + val + '">' + val + '</div>';
		}
		,renderOperate: function(i, val) {
			return '<button data-op="select" class="btn btn-success">' + LANG('选择') + '</button>';
		}
		,onListOpClick: function(ev) {
			var self = this;
			switch(ev.param.op) {
				case 'select':
					self.fire(this.getConfig('selectEvent'), ev.param.data);
					break;
			}
			return false;
		}
	});

	// 活动编辑 —— 从现有活动中复制
	var Main = popwin.extend({
		init:function(config){
			config = pubjs.conf(config, {
				'title': LANG('活动列表'),
				'width': 800,
				'showFoot': true,
				'param': null,
				'class': 'P-campaign-select',
				'silence': false,
				'size': 'm',
				'selectEvent': 'selectCampaign',
				'url': 'campaign/list',
				'buttons': ['cancel', null]
			});

			this.Super('init', arguments);
		},
		afterBuild:function() {
			this.Super('afterBuild', arguments);
			var c = this.getConfig();
			this.create('grid', Grid, {
				param: c['param']
				,url: c['url']
				,selectEvent: c['selectEvent']
			});
		}
		,setParam: function(param) {
			this.$.grid.setParam(param);
			return this;
		}
		,show: function() {
			this.Super('show', arguments);
			this.$.grid.reset().load();
		}
	});

	exports.main = Main;

});